package com.zhang.serviceprice.controller;

import com.zhang.internalcommon.dto.PriceRule;
import com.zhang.internalcommon.dto.PriceRuleIsNewRequest;
import com.zhang.internalcommon.dto.ResponseResult;
import com.zhang.serviceprice.service.PriceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 类功能描述
 *
 * @author Kye
 * @date 2025-04-17
 */
@RestController
@RequestMapping("/price-rule")
public class PriceRuleController {
	@Autowired
	private PriceRuleService priceRuleService;

	@PostMapping("/add")
	public ResponseResult add(@RequestBody PriceRule priceRule) {
		return priceRuleService.add(priceRule);
	}

	@PostMapping("/edit")
	public ResponseResult edit(@RequestBody PriceRule priceRule) {
		return priceRuleService.edit(priceRule);
	}

	@GetMapping("/get-newest-version")
	public ResponseResult<PriceRule> getNewestVersion(@RequestParam String fareType) {
		return priceRuleService.getNewestVersion(fareType);
	}

	@PostMapping("/is-new")
	public ResponseResult<Boolean> isNew(@RequestBody PriceRuleIsNewRequest priceRuleIsNewRequest) {
		// fareType = fareType.replace("%24","$");
		return priceRuleService.isNew(priceRuleIsNewRequest.getFareType(),priceRuleIsNewRequest.getFareVersion());
	}

	/**
	 * 判断这个城市计价规则是否存在
	 * @param priceRule
	 * @return
	 */
	@PostMapping("/if-exists")
	public ResponseResult<Boolean> ifExists(@RequestBody PriceRule priceRule) {
        return priceRuleService.ifExists(priceRule);
	}

}
